﻿
function $(id) {
    return document.getElementById(id);
}
function $$() {
    if (typeof (document.xmlhttp) == "undefined") {

        var xmlhttp;
        if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
            try { xmlhttp = new XMLHttpRequest(); } catch (e) { xmlhttp = false; } //ff, chrome
        }

        if (!xmlhttp && typeof ActiveXObject != "undefined") {
            try { xmlhttp = new ActiveXObject("MSXML2.XMLHTTP"); } catch (e) { xmlhttp = false; } //ie6
            if (!xmlhttp) try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { xmlhttp = false; } //ie7, ie8
        }
        
        document.xmlhttp = xmlhttp;
    }
    return document.xmlhttp;
}


function ShowProduct(e) {

    if (typeof (e.state) == "undefined")
        e.state = false;

    e.state = !e.state;

    // set leaf icon
    var img = e.getElementsByTagName("img").item(0);
    var leaf = e.state ? "iOpen" : "iClosed";
    img.src = $(leaf).src;


    // show or hide family list
    var ul = e.getElementsByTagName("ul").item(0);
    ul.style.display = e.state ? "block" : "none";
}

function OnFamilySelected(ff, e, familyId) {

    if (typeof (document.selectedFamily) == "undefined")
        document.selectedFamily = e;
    else
        document.selectedFamily.className = null;

    // save selected family element globally
    document.selectedFamily = e;

    // set class name
    e.className = "SelectedFamily";


    ShowFamilyAsyn(document.selectedFamily.id, $("stLang").value, 0);


    if (window.event)
        window.event.cancelBubble = true;
    else
        ff.stopPropagation();
}

function OnLocaleChanged(e) {

    if (typeof (document.selectedFamily) == "undefined")
        return;

    ShowFamilyAsyn(document.selectedFamily.id, e.value, 0);
}

function ShowFamilyAsyn(familyId, locale, sort) {

    // temporary disable this function for static html page usage!
    return;

    // show spinner and hide others
    $("logoAnchor").focus();
    $("ResultsDiv").style.display = "none";
    $("SearchDiv").style.display = "none";
    $("spinner").style.display = "";

    // invoke server request
    var pv = familyId + ":" + locale + ":" + sort;

    $$().open("GET", "ShipProvider.ashx?pv=" + pv, true);
    $$().onreadystatechange = ShowFamilyComplete;
    $$().send(null);
}

function ShowFamilyComplete() {
    if ($$().readyState == 4) {
        var source = $$().responseText;

        if (source.length == 0) {
            $("ResultsDiv").style.display = "none";
            $("spinner").style.display = "none";

            var div = $("SearchDiv");
            div.style.display = "";
        }
        else {
            $("SearchDiv").style.display = "none";
            $("spinner").style.display = "none";

            var div = $("ResultsDiv");
            div.innerHTML = source;
            div.style.display = "";
        }
    }
}

function ShowDetails(cid) {

    var e = $("cell$" + cid);
    if (typeof (e.state) == "undefined")
        e.state = false;

    e.state = !e.state;
    e.style.display = e.state ? "" : "none";

    // for google-tracking
    window.location.hash = cid;
    switch(cid % 5)
    {
        case 0:
            $("ga-tracking").src = "msdn/windows7-professional/";
            break;
        case 1:
            $("ga-tracking").src = "msdn/windows7-professional-vl/";
            break;
        case 2:
            $("ga-tracking").src = "msdn/windows7-ultimate/";
            break;
        case 3:
            $("ga-tracking").src = "search/#sharepoint-designer-2007";
            break;
        case 4:
            $("ga-tracking").src = "search/#microsoft-visual-studio-2010";
            break;
    }
}

function ShowToolTip(evnt, text) {
}
function HideToolTip() {
}

function SetSort(key)
{
    ShowFamilyAsyn(document.selectedFamily.id, $("stLang").value, key);
}